<template>
  <div>
    <van-cell-group border>
      <van-field
        v-model="password"
        label="注册"
        placeholder="请输入密码"
        autofocus
      />
    </van-cell-group>
    <div class="loginBtn">
      <van-button type="danger" round block :disabled="flag" @click="toregister"
        >完成</van-button
      >
    </div>
  </div>
</template>

<script>
import { DoRegister } from "@/request/api";
export default {
  data() {
    return {
      tel: "",
      // flag是不是需要依赖我们的 tel来计算它的true和false
      password: "",
    };
  },
  computed: {
    flag() {
      if (
        // 必须包含小写，大写数字，最少6位
        /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])\S*$/.test(
          this.password
        )
      ) {
        return false;
      } else {
        return true;
      }
    },
  },
  methods: {
    toregister() {
      DoRegister({
        tel: localStorage.getItem("tel"),
        password: this.password,
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          console.log("注册成功");
          this.$router.go(-3)
        }
      });
    },
  },
};
</script>

<style>
.loginBtn {
  width: 80%;
  margin: 20px auto;
}
</style>